
//
//  StatusRetweetedCell.swift
//  weibo10
//
//  Created by 猎人 on 15/10/27.
//  Copyright © 2015年 hunter. All rights reserved.
//

import UIKit

class StatusRetweetedCell: StatusCell {
    
    override var viewModle: StatusViewModel? {
        didSet {
            
            pictureView.snp_updateConstraints(closure: { (make) -> Void in
                retweetedLabel.text = viewModle?.retweetedText
                
                // 根据配图数量，决定配图视图的顶部间距
                let offset = viewModle?.thumbnailUrls?.count == 0 ? 0 : StatusCellMagrin
                make.top.equalTo(retweetedLabel.snp_bottom).offset(offset)
            })
        }
    }

    override func setupUI() {
        super.setupUI()
        
        //1. 添加控件
        contentView.insertSubview(backButton, belowSubview: pictureView)
        contentView.insertSubview(retweetedLabel, aboveSubview: backButton)
        //2. 自动布局
        //1> 背景图片
        backButton.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(contentLabel.snp_bottom).offset(StatusCellMargin)
            make.left.equalTo(contentView.snp_left)
            make.right.equalTo(contentView.snp_right)
            make.bottom.equalTo(bottomView.snp_top)
        }
        
        // 2> 转发标签
        retweetedLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(backButton.snp_top).offset(StatusCellMargin)
            make.left.equalTo(backButton.snp_left).offset(StatusCellMargin)
        }
        // 3> 配图视图
        pictureView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(retweetedLabel.snp_bottom).offset(StatusCellMargin)
            make.left.equalTo(retweetedLabel.snp_left)
            make.width.equalTo(300)
            make.height.equalTo(90)
        }
        
        
    }
    
    //懒加载控件
    private lazy var backButton: UIButton = {
        
        let button = UIButton()
        
        button.backgroundColor = UIColor(white: 0.8, alpha: 1)
        
        return button
    }()
    
    private lazy var retweetedLabel: UILabel = UILabel(
        title: "转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博转发微博",
        fontSize: 14,
        color: UIColor.darkGrayColor(),
        screenInset: StatusCellMagrin
    )
    
    

}
